import zhipuai


def ai():

    zhipuai.api_key = "41805a5412196acfdd9d63a905f9039a.Z0TWy2173NoP1ZkI"

    while True:
        content = input('请输入你想问的问题（输入"退出"可结束对话）：')
        if content == "退出":
            print("会话结束")
            break

        response = zhipuai.model_api.invoke(
            model="chatglm_lite",
            prompt=[{"role": "user", "content": f"{content}"}],
            temperature=0.9,
            top_p=0.7,
            incremental=True
        )
        print("AI：" + response['data']['choices'][0]['content'])



# 调用函数a()
ai()